import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";
import Login from "./views/Login.vue";
import Welecome from "./views/Welecome.vue";
Vue.use(Router);

var router = new Router({
  routes: [
    {
      path: "/login",
      component: Login
    },
    {
      path: "/home",
      component: Home,
      redirect: "/welecome",
      children: [{ path: "/welecome", component: Welecome }]
    }
  ]
});

//在守卫中对token进行检测
router.beforeEach(function(to, from, next) {
  var token = window.sessionStorage.getItem("token");
  if (token == null && to.path != "/login") {
    next("/login");
  }
  next();
});
